﻿using DataSync.Entity;
using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace DataSync.Proc.CustParse
{
    class DataEnumCustParse : ICustParse
    {
        private static ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public void Init(XElement xmlnode)
        {
            
        }

        public string Parse(string curValue, object[] rowValues, string custParams, CustParseExtData extParams)
        {
            string NewValue = curValue;
            try
            {
                //var CovParam = JsonConvert.DeserializeObject<DataEnumCustParseParams>(custParams);

                if (extParams != null && extParams.DataEnums.ContainsKey(custParams))
                {
                    var enitem = extParams.DataEnums[custParams].SingleOrDefault(e => e.Key == curValue);
                    if (enitem != null)
                    {
                        NewValue = enitem.Value;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Warn(string.Format("格式转换出错:{0}", curValue), ex);
            }
            return NewValue;
        }
    }

    //class DataEnumCustParseParams
    //{
    //    public string Type { get; set; }
    //}
}
